package game;

import java.util.HashMap;
import java.util.Map;

public class GameConfig
{
    // default key
    public static final String  ALLOW_FPSCHANGE = "ALLOW_FPSCHANGE";
    public static final String  DESIRED_FPS     = "DESIRED_FPS";
    public static final String  CONSOLE_ENABLED = "CONSOLE_ENABLED";
    // --
    private final String        TRUE            = "t";
    private final String        FALSE           = "f";
    // attributes
    private Map<String, String> properties;
    
    public GameConfig()
    {
        properties = new HashMap<String, String>();
        // init
        setFalse(ALLOW_FPSCHANGE);
        setInt(DESIRED_FPS, 24);
        setTrue(CONSOLE_ENABLED);
    }
    
    private void setProperty(String key, String value)
    {
        properties.put(key, value);
    }
    
    private String getProperty(Object key)
    {
        String value = properties.get(key);
        if (value == null)
        {
            throw new IllegalArgumentException(key + "is null");
        }
        return value;
    }
    
    public boolean isTrue(String key)
    {
        return TRUE.equals(getProperty(key));
    }
    
    public void setTrue(String key)
    {
        setProperty(key, TRUE);
    }
    
    public boolean isFalse(String key)
    {
        return FALSE.equals(getProperty(key));
    }
    
    public void setFalse(String key)
    {
        setProperty(key, FALSE);
    }
    
    public int getInt(String key)
    {
        return Integer.parseInt(getProperty(key), 16);  
    }
    
    public void setInt(String key, int value)
    {
        setProperty(key, Integer.toHexString(value));
    }
    
    public String getString(String key)
    {
        return getProperty(key);
    }
    
    public void setString(String key, String value)
    {
        setProperty(key, value);
    }
}
